package 困难;

import java.lang.reflect.Array;
import java.util.Arrays;

public class 分发糖果135 {

    public static void main(String[] args) {

    }

    public static int candy(int[] ratings) {
        int[] left = new int[ratings.length];
        int[] right = new int[ratings.length];
        Arrays.fill(left,1 );
        Arrays.fill(right,1 );
        for (int i = 0; i < ratings.length-1; i++) {
            if (ratings[i+1]>ratings[i]){
                left[i+1] = left[i]+1;
            }
        }
        int count = left[left.length - 1];
        for (int i = ratings.length - 2; i >=0; i--) {
            if (ratings[i+1]<ratings[i]){
                right[i] = right[i+1]+1;
            }
            count += Math.max(right[i],left[i] );
        }
        return count;

    }
}
